package Algorithm;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author gthang
 * @description: 二分法
 */
public class TwoSplit {
    public static void main(String[] args) {
        int[] arr = {2,4,1,4,5,7,8,5,4,};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        System.out.println();
    }

    public static int twoSearch(int[] arr,int value){
        int low = 0;
        int high = arr.length - 1;
        while (low <= high){
            int mid = (high - low)/2;
            if (value == arr[mid]){
                return mid;
            }
            if (value > arr[mid]){
                low = mid + 1;
            }
            if (value < arr[mid]){
                high = mid - 1;
            }

        }
        return -1;
    }
}
